package com.example.lin.day9_27.mvp.presenter;

import com.example.lin.day9_27.mvp.model.IMainModel;
import com.example.lin.day9_27.mvp.model.MainModel;
import com.example.lin.day9_27.mvp.view.IMainView;
import com.example.lin.day9_27.pojo.ResultData;
import com.example.lin.day9_27.pojo.User;

public class MainPresenter implements IMainPresenter {


    //Presenter 持有 Model 与 View 的引用.
    private IMainView view;
    private IMainModel model;

    public MainPresenter(IMainView view) {
        this.view = view;
        this.model = new MainModel();
    }

    @Override
    public void login(String user, String psw) {

        //对 user , psw  数据安全 判断 过滤处理.

        model.login(user, psw, new IMainModel.OnLoadCallback() {
            @Override
            public void onSuccess(ResultData<User> resultData) {
                if ("9999".equals(resultData.getCode())) {
                    User data = resultData.getData();
                    if (data != null)
                        view.updateUserInfo(data);


                } else if ("1007".equals(resultData.getCode())) {
                    //失败的逻辑处理
                    view.showErrorInfo(0, resultData.getMsg());
                }
            }

            @Override
            public void onFaild(Throwable e) {

            }
        });
    }


}
